package com.fengxinzi.activity.friend.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fengxinzi.R;
import com.fengxinzi.model.FriendMsg;

public class MsgListViewAdapter extends BaseAdapter{

	private Context mContext;
	private List<FriendMsg> mList;
	
	public MsgListViewAdapter(Context context ,List<FriendMsg> list) {
		super();
		// TODO Auto-generated constructor stub
		this.mContext = context;
		this.mList = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList != null ? mList.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList != null ? mList.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (null == convertView) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_friend_msg, null);
			holder = new ViewHolder();
			holder.mFriendHeader = (ImageView) convertView.findViewById(R.id.friend_list_item_header);
			holder.mFriendName = (TextView) convertView.findViewById(R.id.friend_list_item_name);
			holder.mFriendGender = (ImageView) convertView.findViewById(R.id.friend_list_item_gender);
			holder.mMsgTime = (TextView) convertView.findViewById(R.id.friend_list_item_time);
			holder.mMsgContent = (TextView) convertView.findViewById(R.id.friend_list_item_content);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}
	
	private class ViewHolder{
		private ImageView mFriendHeader;
		private TextView mFriendName;
		private ImageView mFriendGender;
		private TextView mMsgTime;
		private TextView mMsgContent;
	}

}
